let dict = ['南京', '南京市', '长江大桥', '大桥', '市长', '江大桥', '南京市', '欢迎您', '欢迎', '您'],
    sentence = '南京市长江大桥欢迎您';

/* 
 cutting：逆向切割语句
    @params
        dict:匹配的词组
        sentence:需要逆向切割的句子
        num:最大分割长度
    @return 
        所有有效的分割词组
 */
const cutting = function cutting(dict, sentence, num) {
    let result = [];
    const next = () => {
        // 切割语句&和词组进行匹配
        let temp = sentence.slice(-num),
            tempBack = temp;
        while (temp && dict.indexOf(temp) === -1) temp = temp.slice(1);
        if (temp) result.push(temp);
        // 在语句中去掉处理好的temp
        if (!temp) temp = tempBack;
        sentence = sentence.replace(temp, '');
        // 递归继续处理
        if (sentence) next();
    };
    next();
    return result;
};
console.log(cutting(dict, sentence, 5));